package team.kirohuji.domain.user;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import com.fasterxml.jackson.annotation.JsonIgnore;

import team.kirohuji.domain.tidings.Notify;
import team.kirohuji.domain.tidings.Observer;

/**
 * @author kirohuji
 *
 */
@Entity
@Table(name = "user")
public class User implements Serializable{

	private static final long serialVersionUID = -2884315613871623291L;

	/**
	 * 主键
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="user_id")
	private Integer userId;

	/**
	 * 登录名
	 */
	@Column(name="login_name")
	private String loginName;

	/**
	 * 密码
	 */
	private String password;

	/**
	 * 性别
	 */
	private String sex;

	/**
	 * 用户姓名
	 */
	@Column(name="user_name")
	private String userName;

	/**
	 * 用户状态
	 * 0为不在线，1为在线，2为帐号停用
	 */
	@Column(name="account_status")
	private Integer accountStatus;

	/**
	 * 用于加密的盐
	 */
	private String salt;

	/**
	 * 角色列表
	 */
	@JsonIgnore
    @ManyToMany (cascade = CascadeType.REFRESH)
    @JoinTable(name = "user_role", joinColumns = {
            @JoinColumn(name = "fuser_id", referencedColumnName = "user_id")}, inverseJoinColumns = {
            @JoinColumn(name = "frole_id", referencedColumnName = "role_id")})
	private List<Role> roles;
	
	//attendance模块
	@Column(name="team_id")
	private Integer teamId;
	
	
	public Integer getTeamId() {
		return teamId;
	}

	public void setTeamId(Integer teamId) {
		this.teamId = teamId;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public Integer getAccountStatus() {
		return accountStatus;
	}

	public void setAccountStatus(Integer accountStatus) {
		this.accountStatus = accountStatus;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public String toString() {
		return "User [userId=" + userId + ", loginName=" + loginName + ", password=" + password + ", sex=" + sex
				+ ", userName=" + userName + ", accountStatus=" + accountStatus + ", salt=" + salt;
	}
}